package com.ruoyi.web.controller.house;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purpose.domain.HousePurposeT;
import com.ruoyi.purpose.service.IHousePurposeTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋用途Controller
 * 
 * @author lijie
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/house/purpose")
public class HousePurposeTController extends BaseController
{
    @Autowired
    private IHousePurposeTService housePurposeTService;

    /**
     * 查询房屋用途列表
     */
   @GetMapping("/list")
    public TableDataInfo list(HousePurposeT housePurposeT)
    {
        startPage();
        List<HousePurposeT> list = housePurposeTService.selectHousePurposeTList(housePurposeT);
        return getDataTable(list);
    }

    /**
     * 导出房屋用途列表
     */
    @Log(title = "房屋用途", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HousePurposeT housePurposeT)
    {
        List<HousePurposeT> list = housePurposeTService.selectHousePurposeTList(housePurposeT);
        ExcelUtil<HousePurposeT> util = new ExcelUtil<HousePurposeT>(HousePurposeT.class);
        util.exportExcel(response, list, "房屋用途数据");
    }

    /**
     * 获取房屋用途详细信息
     */
   @GetMapping(value = "/{purposeId}")
    public AjaxResult getInfo(@PathVariable("purposeId") Long purposeId)
    {
        return AjaxResult.success(housePurposeTService.selectHousePurposeTByPurposeId(purposeId));
    }

    /**
     * 新增房屋用途
     */
   @Log(title = "房屋用途", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HousePurposeT housePurposeT)
    {
        housePurposeT.setCreater(getUsername());
        return toAjax(housePurposeTService.insertHousePurposeT(housePurposeT));
    }

    /**
     * 修改房屋用途
     */
    @Log(title = "房屋用途", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HousePurposeT housePurposeT)
    {
        housePurposeT.setCreater(getUsername());
        return toAjax(housePurposeTService.updateHousePurposeT(housePurposeT));
    }

    /**
     * 删除房屋用途
     */
   @Log(title = "房屋用途", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purposeIds}")
    public AjaxResult remove(@PathVariable Long[] purposeIds)
    {
        return toAjax(housePurposeTService.deleteHousePurposeTByPurposeIds(purposeIds));
    }
}
